﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Management;

namespace Apmetrix
{

    /**
     * Apmetrix.cs
     * SDK
     * 
     * Created by Jon Holtan on 7/10/2013.
     * Copyright (c) 2012-2013 apMetrix. All rights reserved.
    **/

    /*
     * NOTE: FOR "RELEASE" SET LOG_DEBUG TO FALSE
     */

    //Need to change these constants to reflect PC
    public sealed class ApmetrixConstants
    {
        private static string getOSVersion()
        {
            System.OperatingSystem osInfo = System.Environment.OSVersion;
            
            string osString = "";

            if (osInfo.Version.Major == 6 && osInfo.Version.Minor == 2)
                osString = "8";
            if (osInfo.Version.Major == 6 && osInfo.Version.Minor == 1)
                osString = "7";
            if (osInfo.Version.Major == 6 && osInfo.Version.Minor == 0)
                osString = "Vista";
            if (osInfo.Version.Major == 5 && osInfo.Version.Minor == 1)
                osString = "XP";

           
            return osString;
            
            

        }

        private static string getRes()
        {
            Screen srn = Screen.PrimaryScreen;
            int h = srn.Bounds.Height;
            int w = srn.Bounds.Width;

            string res = w + " x " + h;

            return res;
        }

        public static readonly double LOCATION_UNAVAILABLE = 999;

        private static readonly string OPERATING_SYSTEM = "Windows";
        private static readonly string LIBRARY_VERSION = getOSVersion();

        // constants for logging (set LOG_DEBUG to false for production)
        public static readonly bool LOG_DEBUG = true;

        // constants for database status
        public static readonly int SQLCE_OK = 0;
        public static readonly int SQLCE_ERROR = 1;

        // intent extra used to display broadcast message*
        public static readonly string EXTRA_DISPLAY_MESSAGE = "com.apmetrix.sdk.DISPLAY_MESSAGE";
        public static readonly string EXTRA_DISPLAY_MESSAGE_IN_APP = "com.apmetrix.sdk.DISPLAY_MESSAGE_IN_APP";

        // constants for External IP Address
        public static readonly string EXT_IP_URL = "http://work.apmetrix.com/ip.php";

        // constant for gateway (client server)
        public static readonly string GATEWAY = "http://gw.apmetrix.com:81/gw?";

        // constant for gateway (dev server)
        public static readonly string DEV_GATEWAY = "http://dev.apmetrix.com:81/gw?";

        // constant used to identify invalid unity
        public static readonly int HTTP_SC_IM_A_TEAPOT = 418;

        public static readonly string ScreenHeight = System.Windows.Forms.SystemInformation.VirtualScreen.Height.ToString();

        public static readonly string ScreenWidth = System.Windows.Forms.SystemInformation.VirtualScreen.Width.ToString();

        public static double GetCurrentMilli()
        {
            DateTime Jan1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            TimeSpan javaSpan = DateTime.UtcNow - Jan1970;
            return javaSpan.TotalMilliseconds;
        }

        // class for key constants used when generating event data key/value pairs
        public  class Key
        {
            public static readonly string BRAND = "dv.br";
            public static readonly string END_SESSION = "dv.es";
            public static readonly string GAME_VERSION = "dv.gv";
            public static readonly string GAME_IP_ADDRESS = "dv.ip";
            public static readonly string LATITUDE = "dv.la";
            public static readonly string LONGITUDE = "dv.ln";
            public static readonly string MODEL = "dv.ml";
            public static readonly string OPERATING_SYSTEM = "dv.os";
            public static readonly string BUILD_VERSION = "dv.ov";
            public static readonly string PUSH_NOTIFICATION = "dv.pn";
            public static readonly string HARDWARE_TYPE = "dv.ty";
            public static readonly string GAME_DATASET = "g.d";
            public static readonly string GAME_LIBRARY_VERSION = "g.i";
            public static readonly string GAME_RETURN = "g.r";
            public static readonly string GAME_TIME = "g.t";
            public static readonly string GAME_UNIFIER = "g.u";
            public static readonly string TRANSACTION = "p.t";
            public static readonly string PAGE_VIEW = "pv.p.a_";
            public static readonly string START_SESSION_TIME = "s.s";
            public static readonly string SESSION_REQUEST_COUNT = "s.sc";
            public static readonly string SCREEN_RESOLUTION = "s.sr";
            public static readonly string LAST_REQUEST_TIME = "v.cl";
            public static readonly string INITIAL_SESSION_TIME = "v.fs";
            public static readonly string VISITOR_ID = "v.i";
            public static readonly string LAST_SESSION_LAST_TIME = "v.ll";
            public static readonly string NAME = "name";
            public static readonly string EMAIL = "email";
            public static readonly string REG_ID = "regId";
            public static readonly string TIMER_EVENT_TAG = "timerEventTag";
            public static readonly string TIMER_EVENT_TIME = "timerEventTime";
       
            public static readonly string PAGE_NAME = "p.t";
            public static readonly string PAGE_VIEW_ATTRIBUTE = "pv.p.a_";
  
            public static readonly string CUSTOM_EVENT_TABLE = "pv.cu.t";
            public static readonly string CUSTOM_EVENT_METRIC = "pv.cu.m_";
            public static readonly string CUSTOM_EVENT_KEY = "pv.cu.k";
            public static readonly string CUSTOM_EVENT_DIMENSION = "pv.cu.d_";
        }

        // class for value constants used when generating event data key/value pairs
        public class Value
        {
            public static readonly string START_SESSION = "Start Session";
            public static readonly string END_SESSION = "End Session";
            public static readonly string OPERATING_SYSTEM = "Windows";
            public static readonly string LIBRARY_VERSION = ApmetrixConstants.getOSVersion();
            public static readonly string BRAND = "Microsoft";
            public static readonly string MODEL = "PC";
            public static readonly string VERSION = LIBRARY_VERSION;
            public static readonly string HARDWARE = ApmetrixMotherboardInfo.Manufacturer;
            public static readonly string SCREEN_RES = ApmetrixConstants.getRes();
        }

        
    }
}
